package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Objects;

public class GeneralSimCardTypeAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {
    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Override
    public void onShow(KiteAttr attr, KiteInst inst, AttrData data) {
        KiteOfferInst mainOfferInst = querySceneInstService.getMainOfferInst(data.getSceneInstId());
        if (Objects.nonNull(mainOfferInst)) {
            String offerId = mainOfferInst.getOfferId();
            if (KiteStringUtils.equalsAny(offerId, "50040705", "50040706", "50040701","50040702")) {
                // 去掉eSIM卡， eSIM电子卡
                attr.getAttrValues().removeIf(kiteAttrValue -> KiteStringUtils.equalsAny(kiteAttrValue.getAttrValue(), "100007000", "100007001"));
            }
        }
        super.onShow(attr, inst, data);
    }

    @Override
    public void before(KiteAttr attr, KiteInst inst, String value, AttrData data) {
        /*if (KiteStringUtils.equals("2826", data.getServiceOfferId())) {
            //企业自采
            KiteAttr enterPriseSelfPurchaseAttr = inst.getAttr("200003676");
            if (Objects.nonNull(enterPriseSelfPurchaseAttr)) {
                //企业自采选择值为【是】,卡商要展示
                if ("1_0000106".equals(enterPriseSelfPurchaseAttr.getValue())) {
                    LocalAttrHelper.showAndNonnull(inst, "200004040");
                } else if ("1_0000107".equals(enterPriseSelfPurchaseAttr.getValue())){
                    if (!KiteStringUtils.equals("100007000", attr.getValue())) {
                        LocalAttrHelper.hideAndNullable(inst, "200004040");
                    } else {
                        LocalAttrHelper.showAndNonnull(inst, "200004040");
                    }
                }
            }
            KiteAttr simCardEntitySpec = inst.getAttr("200004041");
            KiteAttr presetElectronicCard = inst.getAttr("200004042");
            KiteAttr eachPhysicalCard = inst.getAttr("200004043");
            if (KiteStringUtils.equalsAny(attr.getValue(), "100007000")) {
                simCardEntitySpec.setShowType("D");
                simCardEntitySpec.setIsNull("F");
                presetElectronicCard.setShowType("D");
                presetElectronicCard.setIsNull("F");
            } else {
                simCardEntitySpec.setShowType("E");
                simCardEntitySpec.setIsNull("T");
                presetElectronicCard.setShowType("E");
                presetElectronicCard.setIsNull("T");
            }
            if (KiteStringUtils.equalsAny(attr.getValue(), "100007000", "100007001")) {
                eachPhysicalCard.setShowType("D");
                eachPhysicalCard.setIsNull("F");
            } else {
                eachPhysicalCard.setShowType("E");
                eachPhysicalCard.setIsNull("T");
            }
        }*/
    }

}
